$(function(){
	
	//美化select
	$('select:not(.origin)').selectpicker({
        style: 'btn-transparent',
    }).on('change', function(){
        $(this).selectpicker({
            style: 'btn-transparent',
        });
    });
	$(document).on('click','.user-info-edit', function () {
		
	});
    $(document).on('click','.comment', function () {
        var id= $(this).attr('data-value');
        layer.open({
            type: 1,
            title: false,
            closeBtn: 0,
            shift: 2,
            shadeClose: true,
            area: ['450px', '320px'], //宽高
            content: $('#invite-comment-'+id)
        });

    });
    $(".need-comment-star li").on("click",function(){
        $(this).addClass("pfxtCur");
        $(this).prevAll().addClass("pfxtCur");
        $(this).nextAll().removeClass("pfxtCur");
    });
    $(".need-comment-star li").dblclick(function(){
        $(".need-comment-star li").removeClass("pfxtCur");
    });

    $(document).on('click','.submit_comment', function () {

        var invite_id = $(this).attr('data-invite_id');
        var form = $('#comments-'+invite_id);
        var data = form.serializeArray();
        var params = {
            url: '/biz/talent/comments',
            type: 'POST',
            dataType: 'json',
            data: data,
        };
        $.ajax(params).done(function(resp){
            if(resp.status == 'true') {
                var data = resp.data;

                var content_html = '<div class=""need-comment-tile lh38"><span class="c85 fl">面试是否前来：</span>';
                if(data.come==1){
                    content_html += '已来';
                }else{
                    content_html += '并未前来';
                }
                content_html += '<div class="clr"></div></div>';

                $('#invite-comment-'+invite_id).find('.company_comments').html(content_html);
                $('#invite-comment-'+invite_id).find('.need-comment-btn').remove();
                layer.closeAll();
                layer.open({title:'系统提示',content:resp.msg});
            }else{
                layer.open({title:'系统提示',content:resp.msg});
            }
        }).fail(function(erro){
            layer.open({title:'系统提示',content:'网络异常...'});
        });
    });
    $(document).on('click','.close_comment', function () {
        layer.closeAll();
    });
    $(document).on('click','.need-btn-cancel', function () {
        layer.closeAll();
    });
    $(document).on('click','.view-resume',function(){
    	var data = {
    			id:$(this).attr('data-rid'),
    			nid:$(this).attr('data-nid'),
    			show:$(this).attr('data-show'),
    	};
    	var iid = $(this).attr('data-uid');
    	viewuserResume(data,iid);
    });
});

/***************************************************************************************************
 * 预约提示日历
 * @type {{}}
 */
//    var showdate = function (n, d) {//计算d天的前几天或者后几天，返回date,注：chrome下不支持date构造时的天溢出
//        var uom = new Date(d - 0 + n * 86400000);
//        uom = uom.getFullYear() + "/" + (uom.getMonth() + 1) + "/" + uom.getDate();
//        return new Date(uom);
//    };
YUI({
    combine: true,
    comboBase: 'http://a.tbcdn.cn/??',
    root: 's/yui/3.3.0/build/',
    filter: {
        'searchExp': "&",
        'replaceStr': ","
    },
    modules: {
        'calendar-skin': {//默认皮肤
            fullpath: '/css/calendar/calendar.css',
            type: 'css'
        },
        'calendar': {
            fullpath: '/js/calendar/calendar.js',
            requires: ['calendar-skin', 'node']
        }
    }
}).use('calendar', 'console', 'dump', function (Y) {
    //静态日历,单击回调
     new Y.Calendar('J_calendar').on('select', function (d) {
        var str = d.getFullYear() + '-' + (d.getMonth()+1) + '-' + d.getDate();
        $.getJSON('/biz/talent/appointmentjson?date=' + str, function (response) {
            var data = response.data;
            var compiled = _.template($('#notice-item-template').html());
            var $list = $('#notice-box'),
                html = (function (data) {
                    var liArr = [];
                    $.each(data, function () {
                        var now = new Date(parseInt(this.interview_at ) * 1000);
                        var y = now.getFullYear();
                        var m = now.getMonth()+1;
                        if (m < 10) m = '0' + m;
                        var d = now.getDate();
                        if (d < 10) d = '0' + d;
                        var h = now.getHours();
                        if (h < 10) h = '0' + h;
                        var i = now.getMinutes();
                        if (i < 10) i = '0' + i;
                        this.interview_at = y + '/' + m + '/' + d + ' ' + h + ':' + i;
                        liArr.push(compiled(this));
                    });
                    return liArr.join('');
                })(data);
            if (html === '')
                html = '<li class="notice"> 今日没有预约哦 :)</li>';
            $list.html(html);
        });
    });

});


/**
 * 查看用户简历
 */
function viewuserResume(data,iid){
    $.ajax({
        'url': '/biz/talent/resume',
        'type': 'GET',
        'data': data,
        error: function (data) {
            layer.open({title: '系统提示', content: '网络异常！'});
        },
        success:function(response){
            if(response.code == 0){
                var result = response.data;
                var html='';
                var experiences='';
                var educationals= '';
                var projects='';
                $.each(result.experiences,function(key,exp){
                    experiences +=  ' <div class="resume-content mr_w840" id="experience">'
                        +'     <div class="list_show" id="list_show_experience" >'
                        +'         <div class="mr_jobe_list">'
                        +'             <div class="clearfix">'
                        +'                 <div class="mr_content_l">'
                        +' 					<div class="l2">'
                        +' 						<a class="projectTitle nourl">'+exp.company_name+'</a>'
                        +' 						<p>'+exp.job+'</p>'
                        +' 					</div>'
                        +' 				</div>'
                        +' 				<div class="mr_content_r">'
                        +' 					<span>'+exp.start_at+' - '+exp.end_at+'</span>'
                        +' 				</div>'
                        +'             </div>'
                        +'             <div class="mr_content_m">'
                        +				exp.content
                        +' 			</div>'
                        +'         </div>'
                        +'     </div>'
                        +' </div>';
                });
                $.each(result.educationals,function(ke,edu){
                    educationals +=' <div class="resume-content mr_w840">'
                        +'     <div class="list_show" id="list_show_educational" >'
                        +'         <div class="mr_jobe_list">'
                        +'             <div class="clearfix">'
                        +'                 <div class="mr_content_l">'
                        +' 					<div class="l2">'
                        +' 						<a class="projectTitle nourl">'+edu.school+'</a>'
                        +' 						<p>'+result.degrees[edu.degree]+'· '+edu.major+'</p>'
                        +' 					</div>'
                        +' 				</div>'
                        +' 				<div class="mr_content_r">'
                        +' 					<span>'+edu.graduated_at+'年毕业</span>'
                        +'  				</div>'
                        +'             </div>'
                        +'         </div>'
                        +'     </div>'
                        +' </div>';
                });
                $.each(result.projects,function(k,prj){
                    projects += '<div class="mr_jobe_list">'
                        +'              <div class="clearfix">'
                        +'                 <div class="mr_content_l">'
                        +' 					<div class="l2">'
                        +' 						<a class="projectTitle nourl">'+prj.name+'</a>'
                        +' 						<p>'+prj.duty+'</p>'
                        +' 					</div>'
                        +' 				</div>'
                        +' 				<div class="mr_content_r">'
                        +' 					<span>'+prj.start_at+' - '+prj.end_at+'</span>'
                        +' 				</div>'
                        +'             </div>'
                        +' 			<div class="mr_content_m">'
                        +				prj.intro
                        +' 			</div>'
                        +'         </div>';
                })
                var signature = '';
                if(result.signature != null && result.signature != undefined  )
                    signature = result.signature;
                var shenfen = '';
                if(result.shenfen != null && result.shenfen != undefined) {
                	shenfen = '		<div class="mb-10">'
                        +'			<span  class="userinfo-show">'
                        +'    		<img src="/images/front/member/home.jpg">'
                        +'    		<span class="ml-10">'+result.shenfen+'</span>'
                        +'			</span>'
                        +'		</div>';
                }
                var basicinfo = '';
                if(data.show == 1){
                	var taghtml = '';
                	$.each(result.tags,function(k,v){
                		if(k<=2){
                			taghtml += '<span style=" background: #fff none repeat scroll 0 0;border: 1px dashed #251716;margin-left: 5px;padding: 0 5px;">'+v.tags_name+'</span>' 
                		}
                	});
                	basicinfo = '<div class="mb-10">'
    				 +'<span  class="userinfo-show">'
    				 +'<span class="ml-10">'
    				 +taghtml
                     +'   &nbsp;&nbsp;&nbsp;&nbsp;'
                     +'   <i class="icon-map-marker"></i>'
                     + result.province+'&nbsp;&nbsp;&nbsp;&nbsp'+result.city
                     +'</span>'
                     +'</span>'
                     +'</div>'
                	+'<div class="mb10">'
                    +'             <span  class="userinfo-show">'
                    +'                 <img src="/images/front/member/call.jpg">'
                    +'                 <span class="ml10">'
                    +'                     '+result.phone+'&nbsp;&nbsp;&nbsp;&nbsp;'
                    +'                     <i class="icon-envelope"></i>&nbsp;'+result.email
                    +'                 </span>'
                    +'             </span>'
                    +'         </div>';
                }
                html='<div class="resume-header">'
                    +'   	<img src="/images/front/member/bg.jpg">'
                    +'       <div class="resume-header-logo">'
                    +'           <img src="'+result.logo+'">'
                    +'     </div>'
                    +' </div>'
                    +' <div class="resume-userinfo">'
                    +'     <div class="resume-userinfo-title mr_w840 mb15">'
                    +'         <span  class="userinfo-show user-name">'+result.user.real_name+'</span>'
                    +'     </div>'
                    +'     <div class="resume-userinfo-center mr_w840 mb15">'
                    +'         <span  class="userinfo-show">'+signature+'</span>'
                    +'     </div>'
                    +'     <div class="resume-userinfo-center mr_w840">'
                    +shenfen
                    +'          <div class="mb10">'
                    +'             <span  class="userinfo-show">'
                    +'                 <img src="/images/front/member/data.jpg">'
                    +'                 <span class="ml10">'
                    +'                     '+result.sex+'&nbsp;&nbsp;'
                    +'                     '+result.age+'岁&nbsp;&nbsp;'
                    +'                     '+result.degrees[result.highest_degree]+'&nbsp;&nbsp;'
                    +                     	result.gznx+'年'
                    +'                 </span>'
                    +'             </span>'
                    +'         </div>'
                    + basicinfo
                    +'     </div>'
                    +' </div>'
                    +' <div class="mr_moudle_head clearfix mr_w840">'
                    +' 	<div class="fl">'
                    +' 		<div class="mr_title">'
                    +' 			<span class="mr_title_l"></span><span class="mr_title_c">工作经历</span><span class="mr_title_r" style="width: 342px"></span>'
                    +' 		</div>'
                    +' 	</div>'
                    +' </div>'
                    +	experiences
                    +' <div class="mr_moudle_head clearfix mr_w840">'
                    +' 	<div class="fl">'
                    +' 		<div class="mr_title">'
                    +' 			<span class="mr_title_l"></span><span class="mr_title_c">教育经历</span><span class="mr_title_r" style="width: 342px"></span>'
                    +' 		</div>'
                    +' 	</div>'
                    +' </div>'
                    + educationals
                    +' <div class="mr_moudle_head clearfix mr_w840">'
                    +' 	<div class="fl">'
                    +' 		<div class="mr_title">'
                    +' 			<span class="mr_title_l"></span><span class="mr_title_c">项目经验</span><span class="mr_title_r" style="width: 342px"></span>'
                    +' 		</div>'
                    +' 	</div>'
                    +' </div>'
                    +' <div class="resume-content mr_w840">'
                    +'     <div class="list_show" id="list_show_projects" >'
                    +		projects
                    +'     </div>'
                    +' </div>'
                    +' <div class="mr_moudle_head clearfix mr_w840">'
                    +' 	<div class="fl">'
                    +' 		<div class="mr_title">'
                    +' 			<span class="mr_title_l"></span><span class="mr_title_c">自我描述</span><span class="mr_title_r" style="width: 342px"></span>'
                    +' 		</div>'
                    +' 	</div>'
                    +' </div>'
                    +' <div class="resume-content mr_w840">'
                    +'    <div class="self_intro clearfix" id="intro_show">'
                    +'     	<div class="fl self-intro-left">'
                    +'     	   <img src="'+result.logo+'" width="80" height="80">'
                    +'     	</div>	';
                if(result.intro != undefined && result.intro != null ){
                    html+= ' <div class="fl self-intro-right" id="other_insert">'
                        +			result.intro
                        +'         </div>';
                }
                html+='     </div>'
                    +' </div>'
                    +' <div class="mr_moudle_head clearfix mr_w840">'
                    +' 	<div class="fl">'
                    +' 		<div class="mr_title">'
                    +' 			<span class="mr_title_l"></span><span class="mr_title_c">期望工作</span><span class="mr_title_r" style="width: 342px"></span>'
                    +' 		</div>'
                    +' 	</div>'
                    +' </div>';
                if(result.needs != undefined && result.needs != null ){
                    html+=' <div class="resume-content mr_w840">'
                        +'     <div class="list_show" >'
                        +'         <div class="mr_jobe_list clearfix" id="expect_show">'
                        +'         	<ul>'
                        +'         	   <li><i class="icon-user-md"></i>&nbsp;&nbsp;'+result.needs.name+'</li>'
                        +'         	   <li><i class="icon-time"></i>&nbsp;&nbsp;'+result.gzxzs[result.needs.job_type]+'</li>'
                        +'         	   <li><i class="icon-map-marker"></i>&nbsp;&nbsp;'+result.needs.cityname+'</li>'
                        +'         	   <li><i class="icon-money"></i>&nbsp;&nbsp;'+result.salarys[result.needs.expect_wages]+'</li>'
                        +'         	</ul>'
                        +'     	</div>'
                        +' 	</div>'
                        +'</div>';
                }

                if ((result.skill_exam_score != undefined && result.skill_exam_score != null) ) {

                    html += ' <div class="mr_moudle_head clearfix mr_w840">'
                        + ' 	<div class="fl">'
                        + ' 		<div class="mr_title">'
                        + ' 			<span class="mr_title_l"></span><span class="mr_title_c">考试成绩</span><span class="mr_title_r" style="width: 342px"></span>'
                        + ' 		</div>'
                        + ' 	</div>'
                        + ' </div>';
                    html += ' <div class="resume-content mr_w840">'
                        + '     <div class="list_show" >'
                        + '         <div class="mr_jobe_list clearfix" id="expect_show">'
                        + '         	<ul>';
                    if (result.skill_exam_score != undefined && result.skill_exam_score != null) {
                        html +='         	   <li class="view_history" data-id="'+result.needs.skill_exam+'" data-uid="'+iid+'">技能测试成绩：&nbsp;&nbsp;' + result.skill_exam_score + '</li>';
                    }

                    html += '         	</ul>'
                        + '     	</div>'
                        + ' 	</div>'
                        + '</div>';
                }
                if(result.resume_status != undefined && result.resume_status != null ){
                    html+= '<div class="mr_self_state company-center-form">'
                        +'	<div class="form_wrap">'
                        +'    <input id="resume_status" name="resume_status" type="button" style="height: 44px;" class="form-control"  value="'+result.resume_status+'">'
                        +'	</div>					'
                        +'</div>';
                }
                $('#myModalLabel').html(result.name+'的简历');
                $('#resumebody').html(html);
                $('#myModal').modal();
            }else{
                layer.open({title:'系统提示',content:response.message});
            }
        }
    });
}

/*******************************************************************************************************************
 * 企业信息
 * */

/**
 * 职位地区，根据父分类获取子分类
 */
function childAreas(pid,uri,id){
    $.ajax({
        'url':'/'+uri,
        'type':'GET',
        'data':'pid='+pid,
        error: function(request) {
            $('#'+id).html('<option value="0">没有更多分类</option>');
        },
        success: function(data){
            if(data.status == 'success'){
                var result = data.data;
                var options ="";
                var firstid;
                if(result.length > 0){
                    $.each(result,function(k,e){
                        if(k==0) firstid=e.area_id;
                        options +='<option value="'+e.area_id+'">'+e.title+'</option>';
                    });
                    if(id == 'city'){
                        childAreas(firstid,uri,'area');
                    }
                    $('#'+id).html(options);
                }else{
                    $('#'+id).html('<option value="0">没有更多分类</option>');
                }
            }else{
                $('#'+id).html('<option value="0">没有更多分类</option>');
            }
        },
    });
}

//检查公司名称可用性
function checkCompany(url,id){
    $.ajax({
        'url':url,
        'type':'GET',
        'error':function(data){
            $("#"+id).html('网络异常！');
        },
        success:function(data){
            if(data.status == 'success'){
                $("#"+id).html(data.msg);
                $("#"+id).css('color','green');
            }else{
                $("#"+id).html(data.msg);
                $("#"+id).css('color','red');
            }
        }
    });
}

//删除标签
function del_tag(obj)
{
    $(obj).parent().remove();
}